import React, { Component } from 'react'

export default class App extends Component {
  constructor(props){
    super(props)
    console.log("Constructor")
    this.state={count:0}
  }
  static getDerivedStateFromProps(props,state){
    console.log("getDerivedStateFromProps",props,state)
    return ""
  }
  //初始化渲染
  componentDidMount(){
    console.log("componentDidMount");
  }
  //控制组件更新
  shouldComponentUpdate(){
    console.log('shouldComponentUpdate');
    return true
  }
  //发生错误时抛出错误点
  componentDidCatch(err,info){
    console.log('componentDidCatch',err,info);
  }
  //快照钩子
  getSnapshotBeforeUpdate(){
    console.log('getSnapshotBeforeUpdate');
    return this.state.count
  }
  //更新完钩子
  componentDidUpdate(preProps,preState,snapshotValue){
    console.log('componentDidUpdate',preProps,preState,snapshotValue);
  }
  //组件销毁前调用
  componentWillUnmount(){
    console.log("componentWillUnmont");
  }
  render() {
    console.log("render")
    return (
      <div id='app'>
        <h2>state的值为{this.state.count}</h2>
        <button onClick={()=>{this.setState({count:this.state.count+1})}}>点击state+1</button>

      </div>
    )
  }
}
